package com.vca.admin.controller;

import com.vca.common.page.CommonPage;
import com.vca.common.request.*;
import com.vca.common.response.AdminHeaderResponse;
import com.vca.common.response.CourseSchedulingAdminByIdResponse;
import com.vca.common.response.CourseSchedulingAdminResponse;
import com.vca.common.result.CommonResult;
import com.vca.common.vo.ExcelCourseSchedulingById;
import com.vca.service.service.CourseSchedulingService;
import com.vca.service.service.SystemGroupDataService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程排课控制器
 *
 * @author Li
 * @date 2022/11/14   15:34
 */
@Slf4j
@RestController("CourseSchedulingController")
@RequestMapping("api/admin/course/scheduling")
@Api(tags = "课程排课控制器")
public class CourseSchedulingController {

    @Autowired
    private CourseSchedulingService courseSchedulingService;

    @Autowired
    private SystemGroupDataService systemGroupDataService;

    /**
     * 课程排课列表
     * @author Li
     * @date 2022/11/14 15:34
     * @return
     */
    @PreAuthorize("hasAuthority('admin:course:scheduling:list')")
    @ApiOperation(value = "课程排课列表")
    @GetMapping("/list")
    public CommonResult<CommonPage<CourseSchedulingAdminResponse>> getList(@ModelAttribute @Validated SchedulingAdminListRequest request, @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage commonPage = CommonPage.restPage(courseSchedulingService.getAdminList(request,pageParamRequest));
        return CommonResult.success(commonPage);
    }

    @PreAuthorize("hasAuthority('admin:course:scheduling:getBookingDetail')")
    @ApiOperation(value = "查看预约明细")
    @GetMapping("/getBookingDetail")
    @ApiImplicitParams(
            @ApiImplicitParam(value = "排期id", name = "排期id")
    )
    public CommonResult<ExcelCourseSchedulingById> getBookingDetail(String id, PageParamRequest pageParamRequest) {
        return CommonResult.success(courseSchedulingService.getBookingDetail(id,pageParamRequest));
    }

    /**
     * 获取课程排课配置信息
     * @author Li
     * @date  2022/11/14   17:24
     * @return
     */
    @ApiOperation(value = "课程排课配置信息")
    @GetMapping("/config")
    public CommonResult getAdminConfig(){
        return CommonResult.success(systemGroupDataService.getCourseSchedulingAdminConfig());
    }

    /**
     * 添加课程排课
     * @author Li
     * @date  2022/11/17   10:50
     * @return
     */
    @PreAuthorize("hasAuthority('admin:course:scheduling:add')")
    @ApiOperation(value = "课程添加排课")
    @PostMapping("/addScheduling")
    public CommonResult addScheduling(@RequestBody SchedulingAddRequest<CourseSchedulingAdminRequest> request){
        return courseSchedulingService.addScheduling(request)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 修改课程排课
     * @author Li
     * @date  2022/11/17   10:50
     * @return
     */
    @PreAuthorize("hasAuthority('admin:course:scheduling:update')")
    @ApiOperation(value = "课程修改排课")
    @PostMapping("/updateScheduling")
    public CommonResult updateScheduling(@RequestBody CourseSchedulingAdminRequest request){
        return courseSchedulingService.updateScheduling(request)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 课程排课日历列表
     * @author Li
     * @date 2022/11/18 14:46
     * @return
     */
    @PreAuthorize("hasAuthority('admin:course:scheduling:calendar')")
    @ApiOperation(value = "课程排课日历列表")
    @GetMapping("/calendarList")
    public CommonResult getCalendarList(@ModelAttribute @Validated SchedulingAdminListRequest request){
        return CommonResult.success(courseSchedulingService.getCalendarList(request));
    }

    /**
     * 跟据课程排期id查询排期
     * @param courseId
     * @author Li
     * @date 2022/11/21 09:47
     * @return
     */
    @ApiOperation(value = "排期id查询排期")
    @GetMapping("/getScheduling")
    public CommonResult<CourseSchedulingAdminByIdResponse> getAdminScheduling(Long courseId){
        return CommonResult.success(courseSchedulingService.getAdminScheduling(courseId));
    }



    /**
     * 跟据课程排期id删除排期
     * @param schedulingId
     * @author Li
     * @since  2022/11/21 14:37
     * @return
     */
    @PreAuthorize("hasAuthority('admin:course:scheduling:delete')")
    @ApiOperation(value = "跟据课程排期id删除排期")
    @GetMapping("/deleteScheduling")
    public CommonResult deleteScheduling(Long schedulingId){
        return courseSchedulingService.deleteScheduling(schedulingId)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 跟据课程id查询排期
     *
     * @param courseId
     * @param pageParamRequest
     * @return
     * @author Li
     * @date 2022/11/21 09:47
     */
    @PreAuthorize("hasAuthority('admin:course:scheduling:get:list')")
    @ApiOperation(value = "跟据课程id查询排期")
    @GetMapping("/getListByCourse")
    public CommonResult<CommonPage<CourseSchedulingAdminByIdResponse>> getListByCourse(Long courseId, @ModelAttribute PageParamRequest pageParamRequest){
        CommonPage commonPage = CommonPage.restPage(courseSchedulingService.getListByCourse(courseId,pageParamRequest));
        return CommonResult.success(commonPage);
    }

    /**
     * @author Li
     * @date  2022/11/24
     * @return
     */
    @ApiOperation(value = "获得课程排期头部数据")
    @GetMapping("/header")
    public CommonResult<List<AdminHeaderResponse>> getHeader(String dateLimit) {
        return CommonResult.success(courseSchedulingService.getHeader(dateLimit));
    }

    /**
     * 上架课程排期预约状态
     * @param courseSchedulingId 课程排期id
     * @author Li
     * @date    2022/11/18 15:16
     * @return
     */
    @PreAuthorize("hasAuthority('admin:course:scheduling:shell:on')")
    @ApiOperation("上架课程排期预约状态")
    @GetMapping("/onShell")
    public CommonResult courseOnShell(Long courseSchedulingId){
        return courseSchedulingService.onShell(courseSchedulingId)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 下架课程排期预约状态
     * @param courseSchedulingId 课程排期id
     * @author Li
     * @date    2022/11/18 15:16
     * @return
     */
    @PreAuthorize("hasAuthority('admin:course:scheduling:shell:off')")
    @ApiOperation("下架课程排期预约状态")
    @GetMapping("/offShell")
    public CommonResult courseOffShell(Long courseSchedulingId){
        return courseSchedulingService.offShell(courseSchedulingId)?CommonResult.success():CommonResult.failed();
    }

    /**
     * @description 取消课程排期
     * @methodName cancel
     * @param request
     * @author Li
     * @date 2022/12/28 16:17
     * @return com.vca.common.result.CommonResult
     */
    @PreAuthorize("hasAuthority('admin:course:scheduling:cancel')")
    @ApiOperation("取消课程排期")
    @PostMapping("/cancel")
    public CommonResult cancel(@RequestBody  SchedulingCancelRequest request){
        return courseSchedulingService.cancel(request)?CommonResult.success():CommonResult.failed();
    }

}
